package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.api.ResultCode;
import com.ytjj.qmyx.admin.model.request.EvaluationProductMatchingRequest;
import com.ytjj.qmyx.admin.model.request.EvaluationProductRequeset;
import com.ytjj.qmyx.admin.model.request.EvaluationRequest;
import com.ytjj.qmyx.admin.service.EvaluationProductService;
import com.ytjj.qmyx.admin.service.ProductService;
import com.ytjj.qmyx.mall.model.EvaluationProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 *
 * @Version: 1.0
 */
@RestController
@RequestMapping("/evaluation")
public class EvaluationProductController {

    @Autowired
    private EvaluationProductService evaluationProductService;

    @Autowired
    private ProductService productService;

    @PostMapping("/list")
    public CommonResult selectList(@RequestBody EvaluationRequest evaluationRequest) {
        return CommonResult.success(evaluationProductService.selectList(evaluationRequest));
    }

    @PostMapping("/insert")
    public CommonResult insertEvaluation(@RequestBody EvaluationProduct evaluationProduct) {
        Integer count = evaluationProductService.insertEvaluation(evaluationProduct);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @GetMapping("/updateStatus")
    public CommonResult updateStatus(@RequestParam Integer id) {
        Integer count = evaluationProductService.updateStatus(id);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @PostMapping("/synvEvaluation")
    public CommonResult syncEvaluationProduct(@RequestBody EvaluationProductRequeset evaluationProduct) {
        return CommonResult.success(productService.syncEvaluationProduct(evaluationProduct));
    }

    @PostMapping("/updateEvaluation")
    public CommonResult updateEvaluation(@RequestBody EvaluationProductRequeset evaluationProductRequeset) {
        return CommonResult.success(evaluationProductService.updateEvaluation(evaluationProductRequeset));
    }

    /**
     * @Description 更新优质测评库商品推荐信息
     *
     *
     *
     * @Version 1.0
     **/
    @PostMapping("/editEvaluationProductMatching")
    public CommonResult editEvaluationProductMatching(@RequestBody EvaluationProductMatchingRequest evaluationProductMatchingRequest) {
        evaluationProductService.editEvaluationProductMatching(evaluationProductMatchingRequest);
        return CommonResult.success(ResultCode.SUCCESS);
    }

    /**
     * @Description 获取测评商品推荐信息
     *
     *
     *
     * @Version 1.0
     **/
    @GetMapping("/getEvaluationProductMatching")
    public CommonResult getEvaluationProductMatching(@RequestParam("productId") Integer productId) {
        return CommonResult.success(evaluationProductService.getEvaluationProductMatching(productId));
    }

    /**
     * @Description 更新测评库活动类型
     *
     *
     *
     * @Version 1.0
     **/
    @GetMapping("/updateEvaluationActivityType")
    public CommonResult updateEvaluationActivityType(@RequestParam("id") Integer id) {
        evaluationProductService.updateEvaluationActivityType(id);
        return CommonResult.success(ResultCode.SUCCESS);
    }
}
